﻿var prop_is_help = false;  //是否帮忙
var prop_deng_list = '';
var prop_tip_list = '';//提示信息
var pub_help_count = 0;
var prop_is_uploadbg = false;

var pub_id = "";


function func_page_init__success(g_api_data, textStatus, jqXHR)
{
	prop_is_help = g_api_data.page.is_help;
	prop_deng_list = g_api_data.page.like_list;
	prop_tip_list = g_api_data.common.entity_abcstr;
	pub_help_count =  g_api_data.page.help_count;

	pub_id = g_api_data.page.entity_actlog__master.actlog_id;


	var hd_img = g_api_data.page.entity_wxuser__master.wxuser_headimgurl;
	var banner = g_api_data.common.entity_abc.abc_pic_top;

	var is_done = g_api_data.page.is_done;

	var prize_type = g_api_data.common.entity_abc.abc_author;//奖品类型
	var qr_img = g_api_data.common.entity_abc.abc_pic_s;
	
	$(".qr_pic").attr('src',img_url(qr_img));
	$(".hd_img").attr('src',func_get_wx_headimgurl(hd_img,64));
	$(".banner").attr('src',img_url(banner));
	
	var rule = g_api_data.common.entity_abcact.abcact_desc.split('\n');
	for (var a= 0; a < rule.length;a++) {
		var html = '<li>'+rule[a]+'</li>';
		$(".rule_content").find('ol').append(html);
	}
	
	for (var i = 0; i < prop_deng_list.length; i++) {
		var item =  prop_deng_list[i];
		var img = item.pic;
		if( item.open ){
			var html = '<div class="deng_item flex active"><img src="'+img_url(img)+'"/></div>'
		}else{
			var html = '<div class="deng_item flex gray"><img src="'+img_url(img)+'"/></div>'
		}

		$(".deng_area").append(html);
	}	
	setItem();
	
	if( is_done ){
		$(".top_tips").html('感谢大家，已经全部点亮');
		$(".bottom_tips").html("区域已经全部点亮");
		
	}else{
		$(".top_tips").html('求帮忙点亮区域');
		$(".bottom_tips").html("已点亮{#help_count}个区域，继续加油".replace("{#help_count}",pub_help_count));
	}
	
	var percent = pub_help_count/prop_deng_list.length*100;
	progress(percent);
}

$(function(){
	$(".btn_wyy").click(function(){
		$(".page_qr").show();
		$(".page_qr_cont").addClass('dialogTop').removeClass('dialogOut')
	})
	$(".page_qr").click(function(){
		$(".page_qr_cont").removeClass('dialogTop').addClass('dialogOut');
		setTimeout(function(){
			$(".page_qr").hide();
			$(".container").show();
		},500)
	})
	$(".page_qr_cont").click(function(e){
		e.stopPropagation();
	})
})

function func_help__success(data, textStatus, jqXHR)
	{
		if(data.errcode == 0)
		{
			$('#toast').toast('你已点亮成功！');
			$(".top_tips").html( prop_tip_list.abcstr_03 );
			prop_is_help = true;
			
			var percent = (pub_help_count+1)/prop_deng_list.length*100;
			progress(percent);
			
			rotateEnd();
			$(".deng_item").eq(pub_help_count).removeClass('gray').addClass('bounceIn');
		}
		else
		{
			$('#toast').toast(data.errmsg);
		}
	}